package com.bwie.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bwie.mapper.CourseMapper;
import com.bwie.pojo.Course;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author GaoYiJie
 * @Description
 * @Create 2025/3/12 10:17
 * @Version 1.0
 */
@Service
public class CourseServiceImpl implements CourseService {

    @Autowired
    CourseMapper courseMapper;

    @Override
    public R getCourseByPage(PageInfoVo pageInfoVo) {
        Page<Course> page = new Page<>(pageInfoVo.getPageNum(), pageInfoVo.getPageSize());

        LambdaQueryWrapper<Course> wrapper = new QueryWrapper<Course>().lambda();
        if (!StringUtils.isEmpty(pageInfoVo.getKeyWord())){
            wrapper.like(Course::getName,pageInfoVo.getKeyWord());
        }
        if (pageInfoVo.getLevel() != null){
            wrapper.eq(Course::getLevel,pageInfoVo.getLevel());
        }
        if (!StringUtils.isEmpty(pageInfoVo.getType())){
            wrapper.eq(Course::getType,pageInfoVo.getType());
        }
        Page<Course> coursePage = courseMapper.selectPage(page, wrapper);
        return R.OK(coursePage);
    }
}
